package com.whfc.wxmp.api.uni.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.uni.dto.CarInoutRecordDTO;
import com.whfc.uni.dto.CarLogDTO;
import com.whfc.uni.dto.CarStatisticalDTO;
import com.whfc.wxmp.api.uni.service.MpCarInoutRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author : qzexing
 * @version : 1.0
 * @date : 2020/6/22 20:44
 */
@RestController
@RequestMapping("/mp/api/car/inout/record")
public class MpCarInoutRecordController extends BaseController {

    @Autowired
    private MpCarInoutRecordService msCarInoutRecordService;


    @GetMapping(value = "/list", params = {"time"})
    public Result list(@CurrentWxUser WxUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "time", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date time,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize) {
        logger.info("获取车辆识别记录列表：loginer:{},pageNum:{},pageSize:{},deptId:{},time:{}",
                user.getName(), pageNum, pageSize, deptId, time);
        PageData<CarInoutRecordDTO> pageData = msCarInoutRecordService.selectRecordList(deptId, time, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping(value = "/list", params = {"date"})
    public Result montList(@CurrentWxUser WxUser user,
                           @RequestParam("deptId") Integer deptId,
                           @RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM") Date date,
                           @RequestParam("pageNum") Integer pageNum,
                           @RequestParam("pageSize") Integer pageSize) {
        logger.info("获取车辆识别记录列表：loginer:{},pageNum:{},pageSize:{},deptId:{},time:{}",
                user.getName(), pageNum, pageSize, deptId, date);
        PageData<CarInoutRecordDTO> pageData = msCarInoutRecordService.selectMontRecordList(deptId, date, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping(value = "/list", params = {"startTime", "endTime"})
    public Result list(@CurrentWxUser WxUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                       @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize) {
        logger.info("获取车辆识别记录列表：loginer:{},pageNum:{},pageSize:{},deptId:{},startTime:{},endTime:{}",
                user.getName(), pageNum, pageSize, deptId, startTime, endTime);
        PageData<CarInoutRecordDTO> pageData = msCarInoutRecordService.selectRecordList(deptId, startTime, endTime, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping(value = "/statistical", params = {"time"})
    public Result getDayStatistical(@CurrentWxUser WxUser user,
                                    @RequestParam("deptId") Integer deptId,
                                    @RequestParam(value = "time") @DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {
        logger.info("车辆统计（天）：loginer:{},deptId:{},time:{}", user.getName(), deptId, time);
        CarStatisticalDTO data = msCarInoutRecordService.getDayStatistical(deptId, time);
        return ResultUtil.success(data);
    }

    @GetMapping(value = "/statistical", params = {"date"})
    public Result getMonthStatistical(@CurrentWxUser WxUser user,
                                      @RequestParam("deptId") Integer deptId,
                                      @RequestParam(value = "date") @DateTimeFormat(pattern = "yyyy-MM") Date date) {
        logger.info("车辆统计（月）：loginer:{},deptId:{},date:{}", user.getName(), deptId, date);
        CarStatisticalDTO data = msCarInoutRecordService.getMonthStatistical(deptId, date);
        return ResultUtil.success(data);
    }

    @GetMapping(value = "/statistical", params = {"startTime", "endTime"})
    public Result getCustomStatistical(@CurrentWxUser WxUser user,
                                       @RequestParam("deptId") Integer deptId,
                                       @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                       @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        logger.info("车辆统计（自定义）：loginer:{},deptId:{},startTime:{},endTime:{}",
                user.getName(), deptId, startTime, endTime);
        CarStatisticalDTO data = msCarInoutRecordService.getMonthStatistical(deptId, startTime, endTime);
        return ResultUtil.success(data);
    }

    @GetMapping(value = "/export", params = {"startTime", "endTime"})
    public Result export(@CurrentWxUser WxUser user,
                         @RequestParam("deptId") Integer deptId,
                         @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                         @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        logger.info("车辆导出（自定义）,loginer:{},deptId：{}，startTime：{}，endTime：{}", user.getName(), deptId, startTime, endTime);
        OssPathDTO data = msCarInoutRecordService.export(deptId, startTime, endTime);
        return ResultUtil.success(data);
    }

    @GetMapping(value = "/export", params = {"date"})
    public Result montExport(@CurrentWxUser WxUser user,
                             @RequestParam("deptId") Integer deptId,
                             @RequestParam(value = "date") @DateTimeFormat(pattern = "yyyy-MM") Date date) {
        logger.info("车辆导出（月）：loginer:{},deptId:{},date:{}", user.getName(), deptId, date);
        OssPathDTO data = msCarInoutRecordService.montExport(deptId, date);
        return ResultUtil.success(data);
    }


    @GetMapping(value = "/export", params = {"time"})
    public Result export(@CurrentWxUser WxUser user,
                         @RequestParam("deptId") Integer deptId,
                         @RequestParam(value = "time") @DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {
        logger.info("车辆导出（天）：loginer:{},deptId:{},time:{}", user.getName(), deptId, time);
        OssPathDTO data = msCarInoutRecordService.export(deptId, time);
        return ResultUtil.success(data);
    }

    @GetMapping("/log")
    public Result carLog(@CurrentWxUser WxUser user,
                         @RequestParam("deptId") Integer deptId,
                         @RequestParam(value = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        logger.info("车辆日志：loginer:{},deptId:{},date:{}", user.getName(), deptId, date);
        CarLogDTO data = msCarInoutRecordService.carLog(deptId, date);
        return ResultUtil.success(data);
    }

}
